# coding=utf-8
"""

"""

import threading

# @Time    :  2024-10-18 18:08:47
# @Author  :  jiangtong
# @Email   :  gingerqgyy@outlook.com
# @Project :  ginger_yl_test_boost
# @File    :  token_data_util


import threading


class TokenStoreSingleton:
    _instance = None
    _lock = threading.Lock()

    def __new__(cls):
        if cls._instance is None:
            with cls._lock:  # 确保只有一个实例被创建
                if cls._instance is None:
                    cls._instance = super(TokenStoreSingleton, cls).__new__(cls)
                    cls._instance._store = {}  # 初始化存储
                    cls._instance._store_lock = threading.Lock()  # 用于控制 store 的操作
        return cls._instance

    @property
    def store(self):
        return self._store

    def get(self, key):
        with self._store_lock:
            return self._store.get(key)

    def set(self, key, value):
        with self._store_lock:
            self._store[key] = value

    def delete(self, key):
        with self._store_lock:
            if key in self._store:
                del self._store[key]


# 原来的 token_store 改为：
token_store = TokenStoreSingleton().store
